package com.ncloud.resman.service.impl;

import com.ncloud.resman.entity.DeviceBase;
import com.ncloud.resman.entity.DeviceServer;
import com.ncloud.resman.mapper.DeviceBaseMapper;
import com.ncloud.resman.mapper.DeviceServerMapper;
import com.ncloud.resman.service.DeviceBaseService;
import com.ncloud.resman.service.DeviceServerService;
import com.ncloud.resman.service.SequenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by shiqiang on 2017/8/15.
 */
@Service
public class DeviceBaseServiceImpl implements DeviceBaseService{
    @Autowired
    private DeviceBaseMapper deviceBaseMapper;
    @Autowired
    private SequenceService sequenceService;

    @Override
    public Long insertDeviceBase(DeviceBase deviceBase) {
        Long id = null;
        if(deviceBase.getDeviceId() == null){
            id = sequenceService.getSequence("device_id_seq");
            deviceBase.setDeviceId(id);
        }
        deviceBase.setCreateDate(new Date());
        deviceBaseMapper.insertDeviceBase(deviceBase);
        return deviceBase.getDeviceId();
    }

    @Override
    public int updateDeviceBase(DeviceBase deviceBase) {
        deviceBase.setUpdateDate(new Date());
        return deviceBaseMapper.updateDeviceBase(deviceBase);
    }

    @Override
    public DeviceBase getDeviceBaseByDeviceId(Long deviceId) {
        return deviceBaseMapper.getDeviceBaseByDeviceId(deviceId);
    }

    @Override
    public int updateDeviceBaseState(Long deviceId, String state) {
        return deviceBaseMapper.updateDeviceBaseState(deviceId,state);
    }

    @Override
    public int deleteDeviceBase(Long deviceId) {
        return deviceBaseMapper.deleteDeviceBase(deviceId);
    }

	@Override
	public int existsDeviceBySnNum(String snNum) {		
		return deviceBaseMapper.existsDeviceBySnNum(snNum);
	}

	@Override
	public Long getDeviceIdBySnNum(String snNum) {
		return deviceBaseMapper.getDeviceIdBySnNum(snNum);
	}
}
